<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>1F钢架E化方案 - 后台管理 - 角色列表</title>
<%@include file="/WEB-INF/common/css.jsp"%>

<%@include file="/WEB-INF/common/topjs.jsp"%>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">

		<%@include file="/WEB-INF/common/admin/header.jsp"%>
		<%@include file="/WEB-INF/common/admin/menu.jsp"%>

		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px;">
				<h3 class="layui-bg-cyan" style="height: 50px;line-height: 50px;padding-left: 5px">钢架暂放状态列表</h3>
				<hr>
				<div>
					<div class="layui-row">
						<button class="layui-btn" onclick="openAddAlert()">
							<i class="layui-icon">&#xe608;</i> 添加钢架暂放状态
						</button>
					</div>
					<table class="layui-table" id="listshow">
						<thead>
							<tr>
								<th>ID</th>
								<th>名称</th>
								<th>排序</th>
								<th>备注</th>
								<th>创建时间</th>
								<th>最后修改时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>

						</tbody>
					</table>
					<div id="pager"></div>
				</div>
			</div>
		</div>

		<%@include file="/WEB-INF/common/admin/footer.jsp"%>

	</div>

	<form id="addAlert" class="layui-form" action=""
		style="margin: 5px; display: none" lay-filter="add">
		<div class="layui-form-item">
			<label class="layui-form-label">钢架暂放状态名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" required lay-verify="required"
					placeholder="请输入名称" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">钢架暂放状态排序</label>
			<div class="layui-input-block">
				<input type="number" name="sort" required lay-verify="required"
					placeholder="请输入钢架暂放状态排序" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<textarea name="beizhu" placeholder="备注"
					class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="add">添加</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	<form id="updateAlert" class="layui-form" action=""
		style="margin: 5px; display: none" lay-filter="update">
		<input type="hidden" name="id" />
		<div class="layui-form-item">
			<label class="layui-form-label">钢架暂放状态名称</label>
			<div class="layui-input-block">
				<input type="text" name="name" required lay-verify="required"
					placeholder="请输入角色" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">钢架暂放状态排序</label>
			<div class="layui-input-block">
				<input type="number" name="sort" required lay-verify="required"
					placeholder="请输入钢架暂放状态排序" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item layui-form-text">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<textarea name="beizhu" placeholder="备注"
					class="layui-textarea"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="update">更新</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
	
	<%@include file="/WEB-INF/common/bottomjs.jsp"%>
	<script>
	function openAddAlert(){
		layer.open({
			type: 1,
			content: $('#addAlert'),
			area: '500px',
			cancel: function(e){
				$("#addAlert").hide();
			}
		});
	}
	
	function initAlert(){
		$("#addAlert").hide();
		$("#updateAlert").hide();
		var form = layui.form;
	  	//监听提交
	  	form.on('submit(add)', function(data){
	    	$.ajax({
	        	url:"${base}/api/dataTempputState/add.api",
	        	type: "post",
	        	headers: Apicheck.getHeaders(),
	        	data: data.field,
	        	success: function(result){
	        		if(result.code == 1001){
	        			layer.msg(result.msg, {icon:6});
	        			layui.form.val("add", {"name":"", "sort":"", "beizhu":""});
	        			showData(page, size);
	        		}else{
	        			layer.msg(result.msg, {icon:5,anim:6});
	        		}
	        	}
	        });
	    	return false;
	  	});
	  	
	  	form.on('submit(update)', function(data){
	    	$.ajax({
	        	url:"${base}/api/dataTempputState/update.api",
	        	type: "post",
	        	headers: Apicheck.getHeaders(),
	        	data: data.field,
	        	success: function(result){
	        		if(result.code == 1001){
	        			layer.msg(result.msg, {icon:6});
	        			showData(page, size);
	        		}else{
	        			layer.msg(result.msg, {icon:5,anim:6});
	        		}
	        	}
	        });
	    	return false;
	  	});
	}
	var page = 1, size = 10;
	function showData(p, s){
		page = p; size = s;
		$("#listshow tbody").html("");
		$.ajax({
			url:"${base}/api/dataTempputState/list.api",
	    	type: "post",
	    	headers: Apicheck.getHeaders(),
	    	data: {page: p,size: s},
	    	success: function(result){
	    		var xtable = new XTable();
	    		xtable.setOption({
	    			type: XTable.NORMAL,
	    			showKey:["id", "name", "sort", "beizhu", "createTime", "updateTime"],
	    			buttons:[{
	    				name: "编辑",
	    				class: "layui-btn layui-btn-success",
	    				click: function(e){
	    					var form = layui.form;
	    					form.val("update", e);
	    					layer.open({
	    						type: 1,
	    						content: $('#updateAlert'),
	    						area: '500px',
	    						cancel: function(e){
	    							$("#updateAlert").hide();
	    						}
	    					});
	    				}
	    			},{
	    				name: "删除",
	    				class: "layui-btn layui-btn-danger",
	    				click: function(e){
	    					layer.open({
    						   title: '权限删除'
    						   ,content: '真要删吗?，千万别手残咯'
    						   ,yes: function(index, layero){
    							   $.ajax({
    							    	url:"${base}/api/dataTempputState/delete.api",
    							    	type: "post",
    							    	headers: Apicheck.getHeaders(),
    							    	data: {id: e.id},
    							    	success: function(result){
    							    		if(result.code == 1001){
    							    			//layer.msg(result.msg, {icon:6});
    							    			location.reload();
    							    		}else{
    							    			layer.msg(result.msg, {icon:5,anim:6});
    							    		}
    							    	}
    							    });
    						   }
    						});
	    				}
	    			}],
	    			data: result.data.list
	    		});
	    		xtable.show("listshow");
	    		//显示分页
	    		var laypage = layui.laypage;
	    		laypage.render({
	    		    elem: $('#pager'),
	    		    curr: result.data.pager.pageNumber,
	    		    limit: 10,
	    		    count: result.data.pager.recordCount, //数据总数，从服务端得到
	    		    jump: function(obj, first){
	    		        //obj包含了当前分页的所有参数，比如：
	    		        if(!first){
	    		        	showData(obj.curr, obj.limit);
	    		        }
	    		    }
	    		});
	    	}
		});
	}
	$(function(){
		initAlert();
		showData(page, size);
	})
</script>
</body>
</html>